package com.ruoyi.web.controller.acitviti;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.workFlow.domain.ActWorkflowFormData;
import com.ruoyi.workFlow.domain.dto.HistoryDataDTO;
import com.ruoyi.workFlow.service.IFormHistoryDataService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @ClassName HistoryFormDataCoroller
 * @Description activiti 工作流程历史记录
 * @Author leizhang
 * Date 2021/11/4 3:36 下午
 * @Version 1.0
 **/
@RequestMapping("/historyFromData")
@RestController
public class HistoryFormDataController extends BaseController {

    @Autowired
    private IFormHistoryDataService formHistoryDataService;

    private Logger LOGGER = LoggerFactory.getLogger(HistoryFormDataController.class);
    /**
     * @param instanceId(业务id)
     * @return com.ruoyi.common.core.domain.AjaxResult
     * @Description :历史记录查询
     * @Author : leizhang
     * @Date 3:38 下午 2021/11/4
     **/
    @GetMapping(value = "/ByInstanceId/{instanceId}")
    public AjaxResult historyFromData(@PathVariable("instanceId") String instanceId) {
        try{
            List<HistoryDataDTO> historyDataDTOS = formHistoryDataService.historyDataShow(instanceId);
            return AjaxResult.success(historyDataDTOS);
        }catch (Exception e) {
            LOGGER.error(instanceId.concat("实例历史记录查询失败"),e.getCause(),e);
            return AjaxResult.error();
        }
    }

    /**历史记录信息查询**/
   @GetMapping("/getHistoryInfo")
    public TableDataInfo getHistoryInfo(ActWorkflowFormData requestParam) throws Exception{
      try{
          startPage();
          List<Map<String, Object>> historyInfo = formHistoryDataService.getHistoryInfo(requestParam);
          return getDataTable(historyInfo);
      }catch (Exception e){
          LOGGER.error("历史记录信息查询",e.getCause(),e);
          throw new Exception(e);
      }
   }
}
